package com.example.arithmeticleetcode.leetcode.dec;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-12-17 10:16
 **/
public class Demo16 {

    private SimpleDateFormat simpleDateFormat =  new SimpleDateFormat("yyyy/MM/dd");

    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        new Demo16().formateDate();
        long endTime = System.currentTimeMillis();
        System.out.println(endTime - startTime);
        long startTime2 = System.currentTimeMillis();
        new Demo16().formateDate2();
        long endTime2 = System.currentTimeMillis();
        System.out.println(endTime2 - startTime2);
    }

    private void formateDate() {

        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    Date date = new Date();
                    String format = simpleDateFormat.format(date);
//                    System.out.println(format);
                }
            }).start();

        }
    }

    private void formateDate2() {

        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    Date date = new Date();
                    String format =  new SimpleDateFormat("yyyy/MM/dd").format(date);
//                    System.out.println(format);
                }
            }).start();

        }
    }

    public List<Integer> minSubsequence(int[] nums) {
        List<Integer> list = new ArrayList<>();
        if (nums.length == 1) {
            list.add(nums[0]);
            return list;
        }
        Arrays.sort(nums);
        int sum = 0;
        for (int num : nums) {
            sum += num;
        }
        int tempSum = nums[nums.length - 1];
        for(int i = nums.length - 2; i >= 0; i--) {
            if (tempSum > (sum - tempSum)) break;
            tempSum += nums[i];
            list.add(nums[i]);
        }
        return list;
    }
}
